package com.winning.pmph.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Data
@Table(name = "book")
@XmlRootElement(name = "book")
@XmlAccessorType(XmlAccessType.FIELD)
public class Book extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * syncStatus
     * 图书状态：已发布
     */
    public static final int BOOK_STATUS_PUBLISHED = 1;

    /**
     * 图书状态：未发布
     */
    public static final int BOOK_STATUS_UNPUBLISHED = 0;

    /**
     * 图书状态：导入失败
     */
    public static final int BOOK_IMPORT_STATUS_FAILED = 2;

    /**
     * 图书状态：导入中
     */
    public static final int BOOK_IMPORT_STATUS_IMPORTING = 3;

    /**
     * 同步状态
     */
    public static Integer SYNC_STATUS_WAITING = 0;
    public static Integer SYNC_STATUS_SUCCESS = 1;
    public static Integer SYNC_STATUS_FAILED_PRODUCER = 2;
    public static Integer SYNC_STATUS_FAILED_CONSUMER = 3;

    /**
     * ID
     */
    @TableId
    private String id;

    /**
     * 图书名称
     */
    @XmlTransient
    private String name;

    /**
     * 书号
     */
    @XmlTransient
    private String isbn;

    /**
     * 状态
     */
    @XmlTransient
    private Integer status;

    /**
     * 失败原因
     */
    private String failureReason;

    /**
     * 版本
     */
    private Integer version;

    /**
     * 图书分类
     */
    private JSONArray category;

    /**
     * 元数据
     */
    private JSONObject metadata;

    /**
     * 0 电子书(只有XMl文件) 1 电子书+增值服务(既有xml文件又有增值服务) 2增值服务(只有增值服务,没有xml文件)
     */
    private Integer bookType;

    /**
     * 当book_type 是1,2时,该字段起作用,质检状态，即付型状态，1未付型，2已付型 只有已付型的图书才能发布和推送
     */
    private Integer qualityStatus;

    /**
     * 标记状态, 0: 未标记, 1: 正在标记, 2: 标记完成;
     */
    private Integer markedStatus;

    /**
     * 标记人
     */
    private String markedBy;

    /**
     * 标记进度
     */
    private String markedRate;

    /**
     * 同步状态;
     */
    @TableField(exist = false)
    private Integer syncStatus;

    @XmlElementWrapper(name = "front_of_book")
    @XmlElement(name = "Article")
    @Transient
    @TableField(exist = false)
    private List<BookArticle> frontArticleList;
    
    @XmlElementWrapper(name = "body_of_book")
    @XmlElement(name = "Article")
    @Transient
    @TableField(exist = false)
    private List<BookArticle> bodyArticleList;

    @XmlElementWrapper(name = "back_of_book")
    @XmlElement(name = "Article")
    @Transient
    @TableField(exist = false)
    private List<BookArticle> backArticleList;

    @TableField(exist = false)
    private List<BookPic> bookPicList = new ArrayList<>();
    @TableField(exist = false)
    private List<BookTable> bookTableList = new ArrayList<>();
    @TableField(exist = false)
    private Set<String> pictureSet = new HashSet<>();
    @TableField(exist = false)
    private List<String> importTime;
    @TableField(exist = false)
    private String operatedTime;

    /**
     * 上传的zip包的位置
     */
    @TableField(exist = false)
    private String zipPath;
    @TableField(exist = false)
    private String analysisPath;

    /**
     * 用于同步,目的是,同步过后防止元数据中的category类型变化
     */
    @TableField(exist = false)
    private JSONObject syncMetadata;

    /**
     * 增值编辑页面,根据ISBN号查询图书信息时,方便提示是否更新了纸书价格
     */
    @TableField(exist = false)
    private String bPrice;
    @TableField(exist = false)
    private String summary;
}
